
const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin');
const VueLoaderPlugin = require('vue-loader/lib/plugin')

module.exports = {
  mode: 'none',
  entry: './src/main.js',
  output: {
    filename: '[name]-[hash:8].bundle.js',
    path: path.join(__dirname, 'dist'),
    chunkFilename: '[name]-[hash:8].bundle.js',
  },
  module: {
    rules: [
      {
        test: /\.vue$/,
        loader: 'vue-loader'
      },
      {
        test: /\.js$/,
        use: {
          loader: 'babel-loader',
          options: {
            // 最新的 babel 不会导致 tree shaking 失效，但我们任然可以强制设置为 'commonjs'
            presets: [
              ['@babel/preset-env', { modules: 'commonjs' }]
            ]
          }
        },
        exclude: /node_modules/
      },
      {
        test: /\.css$/,
        use: [
          'style-loader',
          'css-loader'
        ]
      },
      {
        test: /\.less$/,
        use: ['style-loader', 'css-loader', 'less-loader',],
      },
      {
        test: /\.(jpe?g|png|gif)$/i, //图片文件
        use: {
          loader: 'url-loader',
          options: {
            limit: 5 * 1024,
            esModule: false
          }
        }
      },

    ]
  },
  plugins: [
    new VueLoaderPlugin(),
    new HtmlWebpackPlugin({
      title: 'base-vue',
     // meta: {},
      template: './public/index.html',
      // 给模板注入参数
      templateParameters: {
        BASE_URL: './'
      }
    })
  ]
}